package com.hhf.feicodebackend.core.saver.template;

import com.hhf.feicodebackend.ai.model.enums.CodeGenTypeEnum;
import com.hhf.feicodebackend.ai.model.result.HtmlCodeResult;
import com.hhf.feicodebackend.common.ErrorCode;
import com.hhf.feicodebackend.core.saver.CodeFileSaverTemplate;
import com.hhf.feicodebackend.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * @Author hhf
 * @Date 2025/8/11
 * @Description html 模板
 */
public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {


    @Override
    protected void saveFiles(HtmlCodeResult result, String path) {
        writeToFile(path,"index.html",result.getHtmlCode());
    }

    @Override
    protected CodeGenTypeEnum codeGenType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void validateInput(HtmlCodeResult result) {
        super.validateInput(result);
        if (StringUtils.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"html 代码为空");
        }
    }
}
